package com.exception.demo.web;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.exception.demo.annotation.LogAnnotation;
import com.exception.demo.response.ResultObj;

@RestController
@RequestMapping("/exception")
public class GlobalExceptionController {

	@GetMapping("noHandlerFoundException")
	@LogAnnotation(desc = ("方法未找到"))
	public ResultObj<String> noHandlerFoundException() {
		 
		return ResultObj.success("成功返回数据");
	}
	
	/**
	 * 未指定参数名称时，参数未传或传参只要位置类型对的上，就不会有问题如（id=123&value=test）
	 * 传（id=test&value=1234）会报类型匹配异常
	 * 传（id=123&test=1234）也没问题,只匹配id,value则为空
	 * 按名称匹配,匹配上就有值,匹配不上默认为空
	 */
	@GetMapping("argumentTypeMismatchException")
	@LogAnnotation(desc = ("参数类型异常"))
	public ResultObj<String> argumentTypeMismatchException(Long id, String value) {
		
		return ResultObj.success("成功返回数据");
	}
	
	/**
	 * 指定参数名称,必须按这个传参
	 */
	@GetMapping("argumentPathVariableException")
	@LogAnnotation(desc = ("参数pathVariable异常"))
	public ResultObj<String> argumentPathVariableException(
			@PathVariable("id")Long id, @PathVariable("value")String value) {
		
		return ResultObj.success("成功返回数据");
	}
	
	@GetMapping("illegalArgumentException")
	@LogAnnotation(desc = ("参数个数异常"))
	public ResultObj<String> illegalArgumentException(Long id, String value) {
		
		return ResultObj.success("成功返回数据");
	}
	
	@GetMapping("throwableException")
	@LogAnnotation(desc = ("throwableException异常"))
	public ResultObj<String> throwableException(Long id, String value) {
		
		return ResultObj.success("成功返回数据");
	}
	
	@GetMapping("defaultException")
	@LogAnnotation(desc = ("defaultException异常"))
	public ResultObj<String> defaultException(Long id, String value) {
		
		return ResultObj.success("成功返回数据");
	}
	
}
